<?php

class Admin_Model_Api {

    private $_dbtable;

    public function __construct() {
        $this->_dbtable = new Admin_Model_DbTable_Api();
    }

    /**
     * Get all api information
     * @return type
     */
    public function fetchAll() {
        $selectall = $this->_dbtable->select();
        return $this->_dbtable->fetchAll($selectall);
    }

    /**
     * Add new API Detail.
     * @param type $data
     */
    public function addNewApi($data) {
        $this->_dbtable->insert($data);
    }

    /**
     * Get api details using primary key id.
     * @param type $id
     */
    public function getApiById($id) {
        $select = $this->_dbtable->select();
        $select->where('sr = ?', $id);
        return $this->_dbtable->fetchAll($select);
    }

    /**
     * Get api details by name
     * @param type $name
     * @return type
     */
    public function getApiByName($name) {
        $select = $this->_dbtable->select();
        $select->where('name = ? ', $name);
        return $this->_dbtable->fetchAll($select);
    }

    /**
     * Update API details...
     * @param type $array
     * @param type $apiId
     */
    public function updateApi($array, $apiId) {
        $this->_dbtable->update($array, "sr = $apiId");
    }

    /**
     * Checks if facebook is active or not...
     * @return type
     */
    public function isFacebookActivated() {
        $facebookApiData = $this->getApiByName('facebook');
        return $facebookApiData[0]['active'];
    }

}

